package com.qipay.utils;

import io.jsonwebtoken.lang.Assert;
import org.apache.commons.lang3.StringUtils;

/**
 * Creator: Yao
 * Date:    2017/10/11
 * For:
 * Other:
 */
public class ParamUtils {

    public static String toJson(String params) {

        // check
        Assert.isTrue(StringUtils.isNotBlank(params));

        // init
        StringBuffer buffer = new StringBuffer("{");

        // split
        String[] infos = params.split("&");
        for (String p : infos) {
            String[] q = p.split("=");
            buffer.append(String.format("\"%s\": \"%s\",", q[0], q[1]));
        }

        return buffer.substring(0, buffer.length() - 1) + "}";
    }
}
